﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Presenters;
using University.Workshop.WinApp.Product;
using University.Workshop.Model;

namespace University.Workshop.WinApp.PurchaseReport
{
    public partial class FormPurchaseReportView : Form, IReportPurchase
    {
        PresenterReportPurchase report;
        SaleVariables variable = SaleVariables.Instance;
        PurchaseVariables variablePurchase = PurchaseVariables.Instance;
        Variables flag = Variables.Instance;
        public FormPurchaseReportView()
        {
            InitializeComponent();
            report = new PresenterReportPurchase(this);
        }
        #region IReportSale Members
        public string FilterBy { get { return comboBoxFilterBy.Text; } }
        public string OfProduct { get { return textBoxOfProduct.Text; } }
        public string OfProvider { get { return textBoxOfProvider.Text; } }
        public bool EnabledDateTo { get { return dateTimePickerTo.Enabled; } set { dateTimePickerTo.Enabled = value; } }
        public bool EnabledDateFrom { get { return dateTimePickerFrom.Enabled; } set { dateTimePickerFrom.Enabled = value; } }
        public bool EnabledProviderGroup { get { return groupBoxProvider.Enabled; } set { groupBoxProvider.Enabled = value; } }
        public bool EnabledProductGroup { get { return groupBoxProduct.Enabled; } set { groupBoxProduct.Enabled = value; } }
        public bool EnabledProviderText { get { return textBoxOfProvider.Enabled; } set { textBoxOfProvider.Enabled = value; } }
        public bool EnabledProductText { get { return textBoxOfProduct.Enabled; } set { textBoxOfProduct.Enabled = value; } }
        public DateTime DateFrom { get { return dateTimePickerFrom.Value; } set { dateTimePickerFrom.Value = value; } }
        public DateTime DateTo { get { return dateTimePickerTo.Value; } set { dateTimePickerTo.Value = value; } }
        #endregion
        private void comboBoxFiltterBy_SelectedIndexChanged(object sender, EventArgs e)
        {
            report.EnableAndDisableControls();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonGenerateReport_Click(object sender, EventArgs e)
        {
            string message = report.OnGenerateReport();

            if (message != "Reporte generado exitosamente!")
                MessageBox.Show(this, message, "Reporte error", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
        }

        private void buttonSelectProduct_Click(object sender, EventArgs e)
        {
            flag.Product = "BrowserProductSale";
            FormProductView productView = new FormProductView();
            productView.ShowDialog();
            if (!string.IsNullOrEmpty(variable.ProductCode))
            {
                textBoxOfProduct.Text = variable.ProductCode;
            }
        }

        private void buttonSelectProvider_Click(object sender, EventArgs e)
        {
            flag.Provider = "BrowserProviderPurchase";
            FormProviderView providerView = new FormProviderView();
            providerView.ShowDialog();
            if (!string.IsNullOrEmpty(variablePurchase.ProviderCode))
            {
                textBoxOfProvider.Text = variablePurchase.ProviderCode;
            }
        }
    }
}
